//编辑固定IP
(function($){
	$(function(){
		var resizePage = (function () {
            $("body,.pop-page").height($(window).height());
            var ww = $(window).width(),
                wh = $("body").innerHeight(),
                popTopH = $(".pop-top").outerHeight(true),
                popFootH = $(".pop-foot").outerHeight(true),
                $wrap = $(".pop-wrap");

            $wrap.height(wh - popTopH - popFootH);
            return arguments.callee;
        })();

        $(window).resize(resizePage);
        
        var top = window.parent;
        //关闭弹出层
        $(".close-pop").on("click",function(e){
        	e.stopPropagation();
        	top.$.popHide();
        });
        
        //获取初始化编辑值
        var editData = top.getData();
        
        //IP段赋值
        $("#editIp").text(editData.ip);
        
      	//网关输入
      	$("#editGateway").ipBox({
      		port : false,
            titleText : "网关",
            titleOut : true,
            ipValue : editData.gateway,
            noPoint : true
      	})
      	//DNS输入
      	$(".editDns").ipBox({
      		port : false,
            titleText : "DNS",
            titleOut : true,
            ipValue : editData.dns,
            noPoint : true
      	})
      	
      	//IP相关操作
      	$(".pop-wrap")
			//新增DNS      		
      		.on("click",".add-dns-btn",function(e){
      			e.stopPropagation();
      			createDns();
				$(".pop-wrap").scrollTop($(".pop-wrap")[0].scrollHeight);
      		})
      		//删除新增的DNS
      		.on("click",".del-dns-btn",function(e){
      			e.stopPropagation();
      			$(this).closest(".new-dns").remove();
      		})
      		
      	//新增DNS方法
      	function createDns(str){
      		var defaultVal = !!str ? str : "";
      		var newDns = $('<div class="new-dns">'+
							'<div class="add-dns c-f"></div>'+
							'<a class="del-dns-btn del-ip ip_btn"><span class="del-ip-btn num_icon"></span></a>'+
							'</div>');
			$(newDns).appendTo($("#dnsPanel")).ipBox({
				port : false,
		        titleText : "",
		        titleOut : true,
		        ipValue : defaultVal,
		        noPoint : true
			});
      	}
      	
      	//内容区域添加滚动条
      	$(".pop-wrap").niceScroll({
      		cursorcolor:"#0099ff",
            autohidemode:false
      	})
       
	})
})(jQuery)
